<!DOCTYPE html>
<html lang="zh-cn" class="no-js">
	<head>
		<meta http-equiv="Content-Type">
		<meta content="text/html; charset=utf-8">
		<meta charset="utf-8">
		<title>欢乐攻城</title>
		<meta name="viewport" content="target-densitydpi=device-dpi, width=750px, user-scalable=no">
		<meta name="format-detection" content="telephone=no">
		<meta name="format-detection" content="email=no">
		<script src="/hlgc/js/zepto.min.js"></script>
		<script type="text/javascript">
		function adaptscreen(widthnum){
			try{
			 var DEFAULT_WIDTH = widthnum, // 页面的默认宽度
		        ua = navigator.userAgent.toLowerCase(), // 根据 user agent 的信息获取浏览器信息
		        deviceWidth = window.screen.width, // 设备的宽度
		        devicePixelRatio = window.devicePixelRatio || 1, // 物理像素和设备独立像素的比例，默认为1
		        targetDensitydpi;    // Android4.0以下手机不支持viewport的width，需要设置target-densitydpi
		        if (ua.indexOf("android") !== -1 && parseFloat(ua.slice(ua.indexOf("android")+8)) < 4) {
		        	targetDensitydpi = DEFAULT_WIDTH / deviceWidth * devicePixelRatio * 160;
		        	$('meta[name="viewport"]').attr('content', 'target-densitydpi=' + targetDensitydpi + ', width=device-width, user-scalable=no');
				}else{
					$('meta[name="viewport"]').attr('content', 'target-densitydpi=device-dpi, width='+DEFAULT_WIDTH+'px, user-scalable=no');
				}
			}catch(e){
				console.log('dpi error',e);
			}
	    }
	    adaptscreen(750);
		</script>
		<link rel="stylesheet" type="text/css" href="/hlgc/css/reset.css?v=1" />
		<link rel="stylesheet" type="text/css" href="/hlgc/css/index.css?v=2" />
		<link rel="stylesheet" type="text/css" href="/hlgc/css/animations.css?v=1" />
        <link rel="stylesheet" type="text/css" href="/hlgc/css/load.css?v=1" /> 
	</head>
	<body>

    <div id="loadingPage" class="loading-page">
	    <div class="loading-page-inn">
		    <div class="soldier">
		     	<img src="./imgs/soldier-mao-small.png" />
		     	<img src="./imgs/soldier-dun-small.png" />
		     	<img src="./imgs/soldier-gong-small.png" />
		    </div>
	     	<div class="process"><div class="process-inn"></div></div>
	    </div>
	</div>

    <!-- 加载中 start -->
    <div id="loading">
     	<div class="spinner">
  			<div class="double-bounce1"></div>
  			<div class="double-bounce2"></div>
		</div>
	</div>
	<div id="loadingMask"></div>
    <!-- 加载中 end -->

	<div id="content" class="content-index" style="display:none">
	
		<!-- topbar start -->
		<div class="topbar">
			<div class="marquee">
				<marquee>欢乐攻城，惊喜不断！</marquee>
			</div>

			<ul class="navbar">
				<li class="crown js-btn-crown"></li>
				<li class="menu js-btn-menu">
					<dl class="menu-list hide">
						<dd class="js-btn-warRecord">投资记录</dd>
						<dd>游戏玩法</dd>
						<dd>公众号</dd>
					</dl>
				</li>
			</ul>
		</div>
		<!-- topbar end -->

		<!-- battleground start -->
		<div class="battleground">
			<div class="battleground-tab">
				<span class="tab tab--active tab-wei" data-nation="1">魏国战场</span>
				<span class="tab tab-wu" data-nation="2">吴国战场</span>
				<span class="tab tab-shu" data-nation="3">蜀国战场</span>
			</div>
			<div class="battleground-content">
				<div class="tab-content content-wei">
					<div class="flag">魏</div>
					<div class="city">洛阳</div>
                    <div class="tips-desc">胜利人均掠夺2份金豆粮草</div>
					<div class="record">
						<div class="title"><i class="sword"></i>敌军记录</div>
						<div class="list"></div>
					</div>
				</div>
				<div class="tab-content content-wu hide">
					<div class="flag">吴</div>
					<div class="city">建业</div>
                    <div class="tips-desc">胜利人均掠夺2份金豆粮草</div>
					<div class="record">
						<div class="title"><i class="sword"></i>敌军记录</div>
						<div class="list"></div>
					</div>
				</div>
				<div class="tab-content content-shu hide">
					<div class="flag">蜀</div>
					<div class="city">荆州</div>
                    <div class="tips-desc">胜利人均掠夺2份金豆粮草</div>
					<div class="record">
						<div class="title"><i class="sword"></i>敌军记录</div>
						<div class="list"></div>
					</div>
				</div>
			</div>

			<!-- 金库 start -->
			<div class="vault">
				<div class="title"><i class="treasure"></i>金库</div>
				<div class="count">2567894</div>
			</div>
			<!-- 金库 start -->

			<!-- 攻打 start -->
			<div class="fight">
				<div class="tips-ready hide">准备出战</div>
				<div class="go-fight js-go-fight hide">出战</div>
				<ul class="camp clearfix">
					<li class="mao" data-type="1">
						<div class="single">
							<div class="pic"></div>
							<p class="energy"></p>
							<div class="name">矛兵</div>
						</div>
						<div class="group">
							<div class="pic"></div>
							<p class="energy"></p>
							<div class="name">矛兵×<i class="num"></i></div>
						</div>
					</li>
					<li class="dun" data-type="2">
						<div class="single">
							<div class="pic"></div>
							<p class="energy"></p>
							<div class="name">盾兵</div>
						</div>
						<div class="group">
							<div class="pic"></div>
							<p class="energy"></p>
							<div class="name">盾兵×<i class="num"></i></div>
						</div>
					</li>
					<li class="gong" data-type="3">
						<div class="single">
							<div class="pic"></div>
							<p class="energy"></p>
							<div class="name">弓兵</div>
						</div>
						<div class="group">
							<div class="pic"></div>
							<p class="energy"></p>
							<div class="name">弓兵×<i class="num"></i></div>
						</div>
					</li>
				</ul>

				<!-- 战 start -->
				<div class="fighting hide">
					<div class="step1">
						<div class="enemy hide">
							<div class="name"></div>
							<div class="energy"><div class="process"></div></div>
							<div class="pic pic--dun"></div>
						</div>
						<div class="self">
							<div class="pic pic--dun"></div>
							<div class="energy"><div class="process"></div></div>
							<div class="name"></div>
						</div>
					</div>

					<div class="step2 hide">
						<div class="enemy">
							<div class="name"></div>
							<div class="energy"><div class="process"></div></div>
						</div>
						<div class="animate"></div>
						<div class="self">
							<div class="energy"><div class="process"></div></div>
							<div class="name"></div>
						</div>
					</div>
				</div>
				<!-- 战 end -->

			</div>
			<!-- 攻打 end -->

		</div>
		<!-- battleground end -->

		<!-- bottombar start -->
		<div class="bottombar">
			<div class="my-money">
				<div class="title">我的小妖币</div>
				<div class="money" id="myMoney"></div>
				<a href="/user/usercenter" class="add js-btn-add"></a>
			</div>
			<div class="soldier-option">
				<div class="tips" id="dispatchTips">每出兵100人，消耗100小妖币粮草</div>
				<ul>
					<li class="btn btn--active">100</li>
					<li class="btn">500</li>
					<li class="btn">1000</li>
					<li class="retreat js-btn-retreat">退兵</li>
				</ul>
			</div>
		</div>
		<!-- bottombar end -->

    </div>

    <!-- dialog-relation start -->
    <div class="dialog dialog-relation hide">
		<div class="dialog-mask"></div>
		<div class="dialog-content">
			<div class="pic-relation"></div>
			<div class="jt-btn-goWar go-war dialog-closeBtn">开战</div>
		</div>
    </div>
    <!-- dialog-relation end -->

    <!-- dialog-warResult start -->
    <div class="dialog dialog-warResult hide">
		<div class="dialog-mask"></div>
		<div class="dialog-content">
			<div class="result">
				<div class="pic"></div>
				<div class="tips"></div>
				<div class="number"></div>
			</div>
		</div>
    </div>
    <!-- dialog-warResult end -->

    <!-- dialog-rule start -->
    <div class="dialog dialog-commonStyle dialog-rule hide">
		<div class="dialog-mask"></div>
		<div class="dialog-content">
            <div class="dialog-content-inn">
				<div class="dialog-title">玩法说明</div>
				<div class="dialog-close"></div>

                <div class="main-content">
                    
					<div class="rule-pic"></div>

					<ul class="rule-list">
						<li>矛兵【胜】盾兵、盾兵【胜】弓兵、弓兵【胜】矛兵；</li>
						<li>选择兵种和人数，招募士兵出战，每招募100士兵都消耗100小妖币粮草，战胜或打平在不同模式下掠得不同数量小妖币粮草奖励；</li>
						<li>玩家可以选择不同战场：魏国战场、吴国战场、蜀国战场，胜利人均掠夺2倍小妖币粮草；</li>
						<li>任何以爬虫类工具，以机器人等非人工方式参与游戏的用户，游戏有权不发放奖励，并禁止用户参与。</li>
					</ul>
					
                </div>

            </div>
		</div>
    </div>
    <!-- dialog-rule end -->

    <!-- dialog-warHistory start -->
    <div class="dialog dialog-commonStyle dialog-warHistory hide">
		<div class="dialog-mask"></div>
		<div class="dialog-content">
			<div class="dialog-content-inn">
				<div class="dialog-title">历史出兵</div>
				<div class="dialog-close"></div>

                <div class="main-content">
                    <table>
                        <thead>
                            <tr>
                                <th>出战时间</th>
                                <th>遣兵记录</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>12-30 23:45</td>
                                <td><span class="soldier">盾兵</span></td>
                            </tr>
                            <tr>
                                <td>12-30 23:45</td>
                                <td><span class="soldier">盾兵</span></td>
                            </tr>
                            <tr>
                                <td>12-30 23:45</td>
                                <td><span class="soldier">盾兵</span></td>
                            </tr>
                        </tbody>
                    </table>
                </div>

			</div>
		</div>
    </div>
    <!-- dialog-warHistory end -->

    <!-- dialog-winnersList start -->
    <div class="dialog dialog-commonStyle dialog-winnersList hide">
		<div class="dialog-mask"></div>
		<div class="dialog-content">
			<div class="dialog-content-inn">
				<div class="dialog-title">获奖名单</div>
				<div class="dialog-close"></div>

                <div class="main-content">
                    <table>
                        <thead>
                            <tr>
                                <th colspan="3">这里放文字啊，金库什么的 介绍文字，要不要很长很长</th>
                            </tr>
                        </thead>
                        <tbody>
                            <tr>
                                <td>
                                    <img src="./imgs/eg/head.jpg" />
                                    <span class="name">不能玩啊</span>
                                </td>
                                <td>100万金币</td>
                                <td>12-31 11:22</td>
                            </tr>
                            <tr>
                                <td>
                                    <img src="./imgs/eg/head.jpg" />
                                    <span class="name">不能玩啊</span>
                                </td>
                                <td>100万金币</td>
                                <td>12-31 11:22</td>
                            </tr>
                            <tr>
                                <td>
                                    <img src="./imgs/eg/head.jpg" />
                                    <span class="name">不能玩啊</span>
                                </td>
                                <td>100万金币</td>
                                <td>12-31 11:22</td>
                            </tr>
                        </tbody>
                    </table>
                </div>

			</div>
		</div>
    </div>
    <!-- dialog-winnersList end -->

    <!-- dialog-warRecord start -->
    <div class="dialog dialog-commonStyle dialog-warRecord hide">
		<div class="dialog-mask"></div>
		<div class="dialog-content">
			<div class="dialog-content-inn">
				<div class="dialog-title">攻城记录</div>
				<div class="dialog-close"></div>

                <div class="main-content">
                    <table>
                        <colgroup>
                            <col width="60%">
                            <col width="40%">
                        </colgroup>
                        <tbody>
                            <tr>
                                <td>
                                    <p class="title">盾兵  vs  盾兵 (吴国战场)</p>
                                    <p class="time">12-30 23:24</p>
                                </td>
                                <td>
                                    <p class="result">平</p>
                                    <p class="tips">投注1000金币</p>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <p class="title">盾兵  vs  盾兵 (吴国战场)</p>
                                    <p class="time">12-30 23:24</p>
                                </td>
                                <td>
                                    <p class="result result--success">胜 +256金币</p>
                                    <p class="tips">投注1000金币</p>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <p class="title">盾兵  vs  盾兵 (吴国战场)</p>
                                    <p class="time">12-30 23:24</p>
                                </td>
                                <td>
                                    <p class="result">挑战失败</p>
                                    <p class="tips">投注1000金币</p>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <p class="title">盾兵  vs  盾兵 (吴国战场)</p>
                                    <p class="time">12-30 23:24</p>
                                </td>
                                <td>
                                    <p class="result">平</p>
                                    <p class="tips">投注1000金币</p>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <p class="title">盾兵  vs  盾兵 (吴国战场)</p>
                                    <p class="time">12-30 23:24</p>
                                </td>
                                <td>
                                    <p class="result result--success">胜 +256金币</p>
                                    <p class="tips">投注1000金币</p>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <p class="title">盾兵  vs  盾兵 (吴国战场)</p>
                                    <p class="time">12-30 23:24</p>
                                </td>
                                <td>
                                    <p class="result">挑战失败</p>
                                    <p class="tips">投注1000金币</p>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <p class="title">盾兵  vs  盾兵 (吴国战场)</p>
                                    <p class="time">12-30 23:24</p>
                                </td>
                                <td>
                                    <p class="result">平</p>
                                    <p class="tips">投注1000金币</p>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <p class="title">盾兵  vs  盾兵 (吴国战场)</p>
                                    <p class="time">12-30 23:24</p>
                                </td>
                                <td>
                                    <p class="result result--success">胜 +256金币</p>
                                    <p class="tips">投注1000金币</p>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <p class="title">盾兵  vs  盾兵 (吴国战场)</p>
                                    <p class="time">12-30 23:24</p>
                                </td>
                                <td>
                                    <p class="result">挑战失败</p>
                                    <p class="tips">投注1000金币</p>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <p class="title">盾兵  vs  盾兵 (吴国战场)</p>
                                    <p class="time">12-30 23:24</p>
                                </td>
                                <td>
                                    <p class="result">平</p>
                                    <p class="tips">投注1000金币</p>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <p class="title">盾兵  vs  盾兵 (吴国战场)</p>
                                    <p class="time">12-30 23:24</p>
                                </td>
                                <td>
                                    <p class="result result--success">胜 +256金币</p>
                                    <p class="tips">投注1000金币</p>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <p class="title">盾兵  vs  盾兵 (吴国战场)</p>
                                    <p class="time">12-30 23:24</p>
                                </td>
                                <td>
                                    <p class="result">挑战失败</p>
                                    <p class="tips">投注1000金币</p>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <p class="title">盾兵  vs  盾兵 (吴国战场)</p>
                                    <p class="time">12-30 23:24</p>
                                </td>
                                <td>
                                    <p class="result">平</p>
                                    <p class="tips">投注1000金币</p>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <p class="title">盾兵  vs  盾兵 (吴国战场)</p>
                                    <p class="time">12-30 23:24</p>
                                </td>
                                <td>
                                    <p class="result result--success">胜 +256金币</p>
                                    <p class="tips">投注1000金币</p>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <p class="title">盾兵  vs  盾兵 (吴国战场)</p>
                                    <p class="time">12-30 23:24</p>
                                </td>
                                <td>
                                    <p class="result">挑战失败</p>
                                    <p class="tips">投注1000金币</p>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <p class="title">盾兵  vs  盾兵 (吴国战场)</p>
                                    <p class="time">12-30 23:24</p>
                                </td>
                                <td>
                                    <p class="result">平</p>
                                    <p class="tips">投注1000金币</p>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <p class="title">盾兵  vs  盾兵 (吴国战场)</p>
                                    <p class="time">12-30 23:24</p>
                                </td>
                                <td>
                                    <p class="result result--success">胜 +256金币</p>
                                    <p class="tips">投注1000金币</p>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <p class="title">盾兵  vs  盾兵 (吴国战场)</p>
                                    <p class="time">12-30 23:24</p>
                                </td>
                                <td>
                                    <p class="result">挑战失败</p>
                                    <p class="tips">投注1000金币</p>
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </div>

				<div class="dialog-btns">
					<a href="javascript:;" class="lucky js-btn-lucky">金币抽奖</a>
					<a href="javascript:;" class="continue dialog-closeBtn">继续挑战</a>
				</div>
			</div>
		</div>
    </div>
    <!-- dialog-warRecord end -->

	<script src="/hlgc/js/index.js?v=1"></script>
	<script src="https://code.createjs.com/soundjs-0.6.2.min.js"></script>
    <script type="text/javascript">
	document.onreadystatechange = loading;
	var loading_pc_num=0;
	var loading_pc=setInterval(function(){
		loading_pc_num+=parseInt(Math.random()*20);
		$('.loading-page .process-inn').css('width', Math.min(100, loading_pc_num) + '%');
		if(loading_pc_num>90){
			clearInterval(loading_pc);
		}
	},100);

	function loading(){
		if(document.readyState == "complete"){
			setTimeout(function(){
				loading_pc_num=100;
				startpage();
			},500);
		}
	}

	function startpage(){
		$("#loadingPage").hide();
		$("#content").show();
		//goNext();
	}

	$(function(){
		var baseDispatchPeople = 100; // 基础派遣人数[100, 500, 1000]
		var totalDispatchPeople = 0; // 总派遣人数
		var mayUseTotalMoney = 0; // 需要消耗的小妖币数
		var moneyDouble = 1; // 小妖币倍数
		var isFighting = false; // 是否正在战斗
		var soldierClassArray = ['mao', 'dun', 'gong']; // 兵种类名
		var nation = 1; // 默认是 魏
		var victoryID = 'Victory'; // 胜利声音ID 

		// 入口
        (function() {

			// 首次进入，展示攻防关系
			if ( !getCookie('hlgc_firstIn') ) {
				$('.dialog-relation').removeClass('hide');
				setCookie('hlgc_firstIn', true);
			}

			getUserInfo();	// 个人信息
			initEnemyDispatchRecord(); // 初始化攻城记录

			createjs.Sound.registerSound('/hlgc/imgs/victory.wav', victoryID);

		}());

		// 公用弹层事件
		(function() {
			var $dialogMask = $('.dialog-mask');
			var $close = $('.dialog-close');
			var $closeBtn = $('.dialog-closeBtn');

			// mask
			$dialogMask.on('tap', function() {
				$(this).parents('.dialog').addClass('hide');
			});

			// close
			$close.on('tap', function() {
				$(this).parents('.dialog').addClass('hide');
			});

			// closeBtn
			$closeBtn.on('tap', function() {
				$(this).parents('.dialog').addClass('hide');
			});
		}());

		// 获奖名单弹层
		$('.js-btn-crown').on('tap', function() {
			$('.dialog-winnersList').removeClass('hide');
		});

		// 菜单弹层
		(function() {
			// 弹出菜单
			$('.js-btn-menu').on('tap', function() {
				$('.dialog-rule').toggleClass('hide');
			});

			// 投资记录
			$('.js-btn-warRecord').on('tap', function() {
				$('.dialog-warRecord').removeClass('hide');
			});
		}());

        // 敌军记录弹层
        $('.battleground-content .record').on('tap', function() {
            showEnemyDispatchRecord();
        });
		
		// 切换国家
		(function() {
			var $tabs = $('.battleground-tab .tab');
			var $tabContents = $('.battleground-content .tab-content');
			$tabs.on('tap', function() {
                if (isFighting) return;
				var index = $tabs.index($(this));
				nation = index + 1;
				$tabContents.addClass('hide');
				$tabContents.eq(index).removeClass('hide');
				$tabs.removeClass('tab--active');
				$(this).addClass('tab--active');
			});
		}());

		// 选择出兵基数
		$('.soldier-option li.btn').on('tap', function() {
			$(this).addClass('btn--active').siblings('.btn').removeClass('btn--active');
			baseDispatchPeople = parseInt( $(this).text() );
			console.log('baseDispatchPeople: ' + baseDispatchPeople);
		});

		// 选择兵种
		$('.camp li').on('tap', function() {
            if (isFighting) return;

			var $target = $(this);
			var $others = $target.siblings('li');

			$('.tips-desc, .tips-ready').addClass('hide');
			$('.js-go-fight').removeClass('hide');

			if ($target.hasClass('select--blur')) {
				// 切换了兵种，重置派遣信息
				totalDispatchPeople = 0;
				mayUseTotalMoney = 0;
				changeDispatchTips();
				$target.append('<div class="animateNumber">+' + baseDispatchPeople + '</div>'); // 数字增加动画
			} else {

				var tempTotalDispatchPeople = totalDispatchPeople + baseDispatchPeople;
				var tempMayUseTotalMoney = mayUseTotalMoney + baseDispatchPeople / 100 * moneyDouble * 100;

				if (tempMayUseTotalMoney > 5000) {
					alert('出兵不能超过5000人哦～');
				} else {
					// 没有切换兵种，累加
					changeDispatchTips();
					// 增加动画
					$target.append('<div class="animateNumber">+' + baseDispatchPeople + '</div>'); // 数字增加动画
				}

			}

			$target.find('.name .num').text(totalDispatchPeople);
			$target.addClass('select--group').removeClass('select--blur');
			$others.removeClass('select--group').addClass('select--blur');
		});

		// 退兵
		$('.js-btn-retreat').on('tap', function() {
			if (isFighting) return;
			$('.camp li').removeClass('select--blur select--group');
			$('.tips-desc').removeClass('hide');
			$('.tips-ready, .js-go-fight').addClass('hide');
			totalDispatchPeople = 0;
			mayUseTotalMoney = 0;
			changeDispatchTips(true);
		});

		// 出战
		$('.js-go-fight').on('tap', function() {
            if (isFighting) return;

            isFighting = true;

            showLoading();

			fighting(
					$('.camp li.select--group').data('type'),
					totalDispatchPeople
				);
		});

		// 改变派遣信息
		function changeDispatchTips(reset) {
			if (reset) {
				totalDispatchPeople = 0;
				mayUseTotalMoney = 0;
				$('#dispatchTips').html('每出兵100人，消耗100小妖币粮草');
			} else {
				totalDispatchPeople += baseDispatchPeople;
				mayUseTotalMoney += baseDispatchPeople / 100 * moneyDouble * 100;

				$('#dispatchTips').html('出兵' + totalDispatchPeople + '人，消耗' + mayUseTotalMoney + '小妖币粮草');
			}
		}

		// 战
		function fighting(selfType, selfEnergy) {
			console.log('自己: ' + soldiersMap(selfType) + ' 能量: ' + selfEnergy);

			$('.fighting .self .name').html( soldiersMap(selfType) + '×' + selfEnergy );
			$('.fighting .self .pic')[0].className = 'pic pic--' + soldierClassArray[selfType -1];

			// ajax请求敌人数据
			$.ajax({
				type: "get",
				url: "/api/hlgc/hand",
				data: {
                    rid: 1,
                    hand: selfType,
                    gold: mayUseTotalMoney,
					nation: nation
				},
				success: function(jdata){
                    hideLoading();
                    
					if (jdata.code == 0) {

                        $('.tips-ready').removeClass('hide');
                        $('.js-go-fight').addClass('hide');
                        $('.camp li').addClass('hide').removeClass('select--blur select--group');
                        $('.fighting').removeClass('hide');

                        var enemyType = getMyEnemy(jdata.data.bet_result, selfType); // 算出我的敌人类型
                        var enemyEnergy = selfEnergy; // 写死敌人人数

                        console.log('敌人: ' + soldiersMap(enemyType) + ' 能量: ' + enemyEnergy);

                        $('.fighting .enemy .name').html( soldiersMap(enemyType) + '×' + enemyEnergy );
                        $('.fighting .enemy .pic')[0].className = 'pic pic--' + soldierClassArray[enemyType -1];
                        $('.fighting .enemy').removeClass('hide');

                        // 靠近动画
                        setTimeout(function() {

                            $('.fighting .step1').addClass('hide');
                            $('.fighting .step2').removeClass('hide');
							$('.animateNumber').remove(); // 删除append进来的增加数字

							// 能量值动画
							setTimeout(function() {
								$('.fighting .step2').addClass('step2--' + jdata.data.bet_result);
							}, 50);

                            // 打架动画
                            setTimeout(function() {
                                $('.fighting, .fighting .step2').addClass('hide');
                                $('.fighting .step1').removeClass('hide');
                                $('.fighting .step1 .enemy').addClass('hide');
                                $('.tips-ready').addClass('hide');
								$('#myMoney').html( parseInt(jdata.data.user_left_xyb * 100) ); // 更新我的小妖币
                                updateEnemyRecord(enemyType);

								judgment( jdata.data.bet_result, parseInt(jdata.data.get_xyb * 100) );
                            }, 1500);

                        }, 1000);

					} else {
						alert(jdata.msg);
                        isFighting = false;
					}
				},
				error: function(){
                    alert('网络异常');
                    hideLoading();
                    isFighting = false;
				}
			});

		}

		// 判决
		function judgment(result, getXYB) {
			changeDispatchTips(true);

			var $resultLayer = $('.dialog-warResult');
			var $result = $resultLayer.find('.result');
			var $numbers = $resultLayer.find('.number');

			$resultLayer.removeClass('hide');

			if(result == 1) {
                // 赢

				createjs.Sound.play(victoryID); 

				$result.addClass('result--win');

				var numbersArray = getXYB.toString().split('');
				var numbersHTML = '';

				for (var i = 0; i < numbersArray.length; i++) {
					numbersHTML += '<img src="/hlgc/imgs/numbers/' + numbersArray[i] + '.png" />';
				}

				numbersHTML = '<img src="/hlgc/imgs/numbers/add.png" />' + numbersHTML;

				$numbers.html(numbersHTML);

			} else if (result == 2) {
                // 输
				$result.addClass('result--lost');
			} else if (result == 3) {
                // 平
				$result.addClass('result--equal');
			}

			// 隐藏结果
			setTimeout(function() {
                
				$resultLayer.addClass('hide');
				
				$result[0].className = 'result';
				$('.camp li, .tips-desc').removeClass('hide');
				$('.fighting .step2')[0].className = 'step2 hide';

				isFighting = false;

			}, 1500)

		}

		// 映射
		function soldiersMap(type) {
			type = type.toString();

			switch(type) {
				case '1':
					return '矛兵';
					break;
				case '2':
					return '盾兵';
					break;
				case '3':
					return '弓兵';
					break;
				default:break;
			}
		}

        // 攻克关系(返回敌人type)
        function getMyEnemy(result, selfType) {

            if (result == 1) {
                // 赢
                if (selfType == 1) {
                    return 2;
                } else if (selfType == 2) {
                    return 3;
                } else if (selfType == 3) {
                    return 1;
                }
            } else if (result == 2) {
                // 输
                if (selfType == 1) {
                    return 3;
                } else if (selfType == 2) {
                    return 1;
                } else if (selfType == 3) {
                    return 2;
                }
            } else if (result == 3) {
                // 平
                return selfType;
            }

        }

        // “战”之后更新敌军记录
        function updateEnemyRecord(newRecord) {
            var $nowBattleground = $('.tab-content').not('.hide');
            var $list = $nowBattleground.find('.record .list');
            var $records = $list.find('span');
            var newRecordHTML = '<span>' + soldiersMap(newRecord).slice(0, 1) + '</span> ';

            $list.prepend(newRecordHTML);

            if ($records.length >= 3) {
                $records.last().remove();
            }
        }

		//写cookies 
		function setCookie(name,value) {
		    var Days = 30; 
		    var exp = new Date(); 
		    exp.setTime(exp.getTime() + Days*24*60*60*1000); 
		    document.cookie = name + "="+ escape (value) + ";expires=" + exp.toGMTString(); 
		} 

		//读取cookies 
		function getCookie(name) {
		    var arr,reg=new RegExp("(^| )"+name+"=([^;]*)(;|$)");
		 
		    if(arr=document.cookie.match(reg))
		 
		        return unescape(arr[2]); 
		    else 
		        return null; 
		} 

		//删除cookies 
		function delCookie(name) {
		    var exp = new Date(); 
		    exp.setTime(exp.getTime() - 1); 
		    var cval=getCookie(name); 
		    if(cval!=null) 
		        document.cookie= name + "="+cval+";expires="+exp.toGMTString(); 
		} 

        // 获取用户信息
        function getUserInfo() {
			$.ajax({
				type: "get",
				url: "/api/hlgc/getUserInfo",
				data: {
				},
				success: function(jdata){
					if (jdata.code == 0) {
						$('#myMoney').html(jdata.data.XYB); // 更新我的小妖币
					} else {
						alert(jdata.msg);
					}
				},
				error: function(){
                    alert('网络异常')
				}
			});
        }

		// 初始化敌军出兵记录
		function initEnemyDispatchRecord() {
			for(var i = 0; i < 3; i++) {
				(function(index) {
					getEnemyDispatchRecord(index + 1, function(jdata) {
						
						var listHTML = '';

						for(var j = 0; j < jdata.data.length; j++) {
							if (j > 2) break;
							listHTML += '<span>' + jdata.data[j].robot_army_label.slice(0, 1) + '</span> ';
						}

						$('.tab-content').eq(index).find('.record .list').html(listHTML);
					});
				}(i))
			}
		}

		// 获取敌军出兵记录列表
        function getEnemyDispatchRecord(nationType, callback) {
			$.ajax({
				type: "get",
				url: "/api/hlgc/record",
				data: {
                    nation: nationType
				},
				success: function(jdata){
                    hideLoading();
					if (jdata.code == 0) {
						
						(typeof callback != 'undefined') && callback(jdata);

					} else {
						alert(jdata.msg);
					}
				},
				error: function(){
                    hideLoading();
                    alert('网络异常');
				}
			});
        }

        // 显示敌军出兵记录列表弹层
        function showEnemyDispatchRecord() {
			showLoading();
            getEnemyDispatchRecord(nation, function(jdata) {
				var listHTML = '';

				for(var i = 0; i < jdata.data.length; i++) {
					listHTML += '<tr>' +
								'    <td>' + jdata.data[i].created_time + '</td>' +
								'    <td><span class="soldier">' + jdata.data[i].robot_army_label + '</span></td>' +
								'</tr>';
				}

				$('.dialog-warHistory table tbody').html(listHTML);
				$('.dialog-warHistory').removeClass('hide');
			});

        }

        // 显示加载中
        function showLoading() {
            $('#loading, #loadingMask').show();
        }

        // 隐藏加载中
        function hideLoading() {
            $('#loading, #loadingMask').hide();
        }

	});
	</script>
	</body>
</html>
